package com.bot.adms.service.impl;

import com.bot.adms.dao.*;
import com.bot.adms.dao.impl.*;
import com.bot.adms.model.bo.ApplyContentBo;
import com.bot.adms.model.bo.ApplyInfoBo;
import com.bot.adms.model.entity.*;
import com.bot.adms.model.vo.*;
import com.bot.adms.service.IAdService;
import com.bot.adms.service.IApplyService;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ApplyServiceImpl implements IApplyService {
    private IAdInfoDao adInfoDao;
    private IAdSpScDetailDao adSpScDetailDao;
    private IAdSpScDetailTextDao adSpScDetailTextDao;
    private IAdSpScDetailPosterDao adSpScDetailPosterDao;
    private IAdSpScDetailVideoDao adSpScDetailVideoDao;
    private ICheckRecordInfoDao checkRecordInfoDao;
    private IApplyInfoDao applyInfoDao;
    private IApplyContentDao applyContentDao;
    private IApplyContentSpScDetailDao applyContentSpScDetailDao;
    private IApplyContentSpScDetailTextDao applyContentSpScDetailTextDao;
    private IApplyContentSpScDetailPosterDao applyContentSpScDetailPosterDao;
    private IApplyContentSpScDetailVideoDao applyContentSpScDetailVideoDao;

    /**
     * 实例化对象
     */
    public ApplyServiceImpl() {
        applyInfoDao = new ApplyInfoDaoImpl();
        applyContentDao = new ApplyContentDaoImpl();
        applyContentSpScDetailDao = new ApplyContentSpScDetailDaoImpl();
        applyContentSpScDetailTextDao = new ApplyContentSpScDetailTextDaoImpl();
        applyContentSpScDetailPosterDao = new ApplyContentSpScDetailPosterDaoImpl();
        applyContentSpScDetailVideoDao = new ApplyContentSpScDetailVideoDaoImpl();
        checkRecordInfoDao = new CheckRecordInfoDaoImpl();
        adInfoDao = new AdInfoDaoImpl();
        adSpScDetailDao = new AdSpScDetailDaoImpl();
        adSpScDetailTextDao = new AdSpScDetailTextDaoImpl();
        adSpScDetailPosterDao = new AdSpScDetailPosterDaoImpl();
        adSpScDetailVideoDao = new AdSpScDetailVideoDaoImpl();

    }
    /**
     * 添加投放申请
     *
     * @param applyInfoBo 投放申请信息，包含 ：申请人姓名 ，联系电话等等
     * @return 是否成功
     */
    @Override
    public Boolean addApply(ApplyInfoBo applyInfoBo) {
        //1.广告信息主表操作
        int flag1 = 0;
        int flag2 = 0;
        int flag3 = 0;
        int flag4 = 0;
        long applyId = 0;
        long contentId = 0;
        long contentDeteilId = 0;
        //1.1获取广告信息业务数据

        //1.2.验证限制条件

        //1.3.将业务转为实体数据
        ApplyInfo applyInfo = new ApplyInfo();
        applyInfo.setProject(applyInfoBo.getProject());
        applyInfo.setLinkManName(applyInfoBo.getLinkManName());
        applyInfo.setTel(applyInfoBo.getTel());
        applyInfo.setStatus(applyInfoBo.getStatus());
        applyInfo.setStartTime(applyInfoBo.getStartTime());
        applyInfo.setEndTime(applyInfoBo.getEndTime());
        applyInfo.setCreateTime(applyInfoBo.getCreateTime());
        applyInfo.setUpdateTime(applyInfoBo.getUpdateTime());
        applyInfo.setSubmitTime(applyInfoBo.getSubmitTime());
        //1.4调用dao层处理数据
        flag1 = applyInfoDao.insertApplyInfo(applyInfo);
        //1.5插入成功后
        if (flag1 > 0) {
            //2.1查询投放申请信息的id
            List<ApplyInfo> applyInfos = applyInfoDao.searchApplyInfo(applyInfo);
            if (applyInfos.size() > 0) {
                applyId = applyInfos.get(0).getId();
            }
            //2.2将申请内容信息转换为实体数据
            ApplyContent applyContent = new ApplyContent();
            applyContent.setApplyId(applyId);
            applyContent.setTitle(applyInfoBo.getApplyContentBo().getTitle());
            applyContent.setSpScType(applyInfoBo.getApplyContentBo().getSpScType());
            applyContent.setLayStyle(applyInfoBo.getApplyContentBo().getLayStyle());

            //2.3调用dao层处理数据
            flag2 = applyContentDao.insertApplyContent(applyContent);
            //2.4插入成功后
            if (flag2 > 0) {
                //3.1获取申请内容的id标识
                List<ApplyContent> applyContents = applyContentDao.searchApplyContent(applyContent);
                if (applyContents.size() > 0) {
                    contentId = applyContents.get(0).getId();
                }
                //循环遍历分屏信息
                for(int item=0;item<applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().size();item++){
                    //3.2将投放申请分屏数据实体化
                    ApplyContentSpScDetail applyContentSpScDetail = new ApplyContentSpScDetail();
                    applyContentSpScDetail.setType(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getType());
                    applyContentSpScDetail.setScId(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getScId());
                    applyContentSpScDetail.setApplyContentId(contentId);

                    //4.3调用dao插入数据
                    flag3 = applyContentSpScDetailDao.insertApplyContentSpScDetail(applyContentSpScDetail);
                    //成功后插入投放详细数据
                    if (flag3 > 0) {
                        //4.1查询光告分屏明细id
                        List<ApplyContentSpScDetail> applyContentSpScDetails = applyContentSpScDetailDao.searchApplyContentSpScDetail(applyContentSpScDetail);
                        if (applyContentSpScDetails.size() > 0) {
                            contentDeteilId = applyContentSpScDetails.get(0).getId();
                        }
                        //4.2根据投放广告类型决定进行哪一项实体化
                        //1文字
                        if (applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getType() == 0){
                            //1.2实体化数据
                            ApplyContentSpScDetailText applyContentSpScDetailText = new ApplyContentSpScDetailText();
                            applyContentSpScDetailText.setImageUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailTextBo().getImageUrl());
                            applyContentSpScDetailText.setLocation(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailTextBo().getLocation());
                            applyContentSpScDetailText.setFontType(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailTextBo().getFontType());
                            applyContentSpScDetailText.setFontSize(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailTextBo().getFontSize());
                            applyContentSpScDetailText.setFontColor(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailTextBo().getFontColor());
                            applyContentSpScDetailText.setTextContent(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailTextBo().getTextContent());
                            applyContentSpScDetailText.setApplyContentSpScDetailId(contentDeteilId);

                            //2.2调用dao处理数据
                            flag4 = applyContentSpScDetailTextDao.insertApplyContentSpScDetailText(applyContentSpScDetailText);
                        }
                        //2.海报
                        else if (applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getType() == 1) {
                            //2.1实体化数据
                            ApplyContentSpScDetailPoster applyContentSpScDetailPoster =new ApplyContentSpScDetailPoster();
                            applyContentSpScDetailPoster.setPosterUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailPosterBo().getPosterUrl());
                            applyContentSpScDetailPoster.setResolution(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailPosterBo().getResolution());
                            applyContentSpScDetailPoster.setApplyContentSpScDetailId(contentDeteilId);

                            //2.2调用dao处理数据
                            flag4 = applyContentSpScDetailPosterDao.insertApplyContentSpScDetailPoster(applyContentSpScDetailPoster);
                        }
                        //3.视频
                        else if (applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getType() == 2){
                            //3.1实体化数据
                            ApplyContentSpScDetailVideo applyContentSpScDetailVideo =new ApplyContentSpScDetailVideo();
                            applyContentSpScDetailVideo.setVideoUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailVideoBo().getVideoUrl());
                            applyContentSpScDetailVideo.setTotalTime(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailVideoBo().getTotalTime());
                            applyContentSpScDetailVideo.setResolution(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(item).getApplyContentSpScDetailVideoBo().getResolution());
                            applyContentSpScDetailVideo.setApplyContentSpScDetailId(contentDeteilId);

                            //3.2调用dao层处理数据
                            flag4 = applyContentSpScDetailVideoDao.insertApplyContentSpScDetailVideo(applyContentSpScDetailVideo);

                        }
                    }
                }


            }
        }
        if (flag1 >0 && flag2 > 0 && flag3 > 0 && flag4 > 0) {
            return true;
        }else{
            //删除数据库数据
            this.deleteApply(applyId);
            return false;
        }
    }

    /**
     * 删除投放申请
     *
     * @param applyId 投放申请id
     *                限制：投放申请为草稿
     * @return是否成功
     */
    @Override
    public Boolean deleteApply(Long applyId) {

        int applyCount = 0;
        int contentCount = 0;
        int detailCount = 0;
        int ptvCount = 0;

        long contentId = 0;
        long detailId = 0;
        long ptvId = 0;

        //1.1根据id查询投放申请内容信息id
        ApplyContent applyContent = new ApplyContent();
        applyContent.setApplyId(applyId);
        List<ApplyContent> applyContents = applyContentDao.searchApplyContent(applyContent);
        contentId = applyContents.get(0).getId();

        //1.2根据申请内容id查询分屏明细信息
        ApplyContentSpScDetail applyContentSpScDetail = new ApplyContentSpScDetail();
        applyContentSpScDetail.setApplyContentId(contentId);
        List<ApplyContentSpScDetail> detailList = applyContentSpScDetailDao.searchApplyContentSpScDetail(applyContentSpScDetail);
        int countLength = detailList.size();
        //遍历查询
        for (ApplyContentSpScDetail detailSpScDetail : detailList) {
            detailId = detailSpScDetail.getId();
            //1.3根据投放分屏明细id以及type查询对应的下级表id
            if (detailSpScDetail.getType()==0){

                //将分屏id封装为对象
                ApplyContentSpScDetailText applyContentSpScDetailText = new ApplyContentSpScDetailText();
                applyContentSpScDetailText.setApplyContentSpScDetailId(detailId);
                //查找分屏号下的数据
                List<ApplyContentSpScDetailText> applyContentSpScDetailTexts = applyContentSpScDetailTextDao.searchApplyContentSpScDetailText(applyContentSpScDetailText);
                long delApplyContentSpScDetailTextId = applyContentSpScDetailTexts.get(0).getId();
                //根据id将对应数据删除
                Integer i1 = applyContentSpScDetailTextDao.deleteApplyContentSpScDetailText(delApplyContentSpScDetailTextId);
                if(i1>0){
                    //删除对应上级表
                    Integer i2 = applyContentSpScDetailDao.deleteApplyContentSpScDetail(detailId);
                    if (i2>0){
                        detailCount++;
                    }
                }
            }
            //海报
            else if (detailSpScDetail.getType()==1){
                //将分屏id封装为对象
                ApplyContentSpScDetailPoster applyContentSpScDetailPoster = new ApplyContentSpScDetailPoster();
                applyContentSpScDetailPoster.setApplyContentSpScDetailId(detailId);
                //查找分屏号下的数据
                List<ApplyContentSpScDetailPoster> applyContentSpScDetailPosters = applyContentSpScDetailPosterDao.searchApplyContentSpScDetailPoster(applyContentSpScDetailPoster);
                long delApplyContentSpScDetailPosterId = applyContentSpScDetailPosters.get(0).getId();
                //根据id将对应数据删除
                Integer i1 = applyContentSpScDetailPosterDao.deleteApplyContentSpScDetailPoster(delApplyContentSpScDetailPosterId);
                if(i1>0){
                    //删除对应上级表
                    Integer i2 = applyContentSpScDetailDao.deleteApplyContentSpScDetail(detailId);
                    if (i2>0){
                        detailCount++;
                    }
                }
            }
            //视频
            else if (detailSpScDetail.getType()==2){
                //将分屏id封装为对象
                ApplyContentSpScDetailVideo applyContentSpScDetailVideo = new ApplyContentSpScDetailVideo();
                applyContentSpScDetailVideo.setApplyContentSpScDetailId(detailId);
                //查找分屏号下的数据
                List<ApplyContentSpScDetailVideo> applyContentSpScDetailVideos = applyContentSpScDetailVideoDao.searchApplyContentSpScDetailVideo(applyContentSpScDetailVideo);
                long delApplyContentSpScDetailVideoId = applyContentSpScDetailVideos.get(0).getId();
                //根据id将对应数据删除
                Integer i1 = applyContentSpScDetailVideoDao.deleteApplyContentSpScDetailVideo(delApplyContentSpScDetailVideoId);
                if(i1>0){
                    //删除对应上级表
                    Integer i2 = applyContentSpScDetailDao.deleteApplyContentSpScDetail(detailId);
                    if (i2>0){
                        detailCount++;
                    }
                }
            }
        }
        //验证底层信息删除是否成功
        if (detailCount == countLength){
            //删除投放申请内容
            contentCount = applyContentDao.deleteApplyContent(contentId);
        }
        //删除内容过后删除广告信息以及审核信息，最后删除投放申请
        if (contentCount > 0){
            //1.根据投放申请id查询审核信息
            //1.2根据审核信息id删除审核信息
            CheckRecordInfo checkRecordInfo = new CheckRecordInfo();
            checkRecordInfo.setApplyId(applyId);
            List<CheckRecordInfo> checkRecordInfos = checkRecordInfoDao.searchCheckRecordInfo(checkRecordInfo);
            //如果有则删除审核记录
            if (checkRecordInfos.size() > 0){
                for (CheckRecordInfo checkRecordInfo1 : checkRecordInfos){
                    checkRecordInfoDao.deleteCheckRecordInfo(checkRecordInfo1.getId());
                }
            }
            //2.根据投放申请id查询广告信息
            AdInfo adInfo = new AdInfo();
            adInfo.setApplyId(applyId);
            List<AdInfo> adInfos = adInfoDao.searchAdInfo(adInfo);
            //2.2如果有广告信息则删除
            if (adInfos.size() > 0){
                IAdService adService = new AdServiceImpl();
                adService.deleteAd(adInfos.get(0).getId());
            }

            //删除投放申请
            applyCount = applyInfoDao.deleteApplyInfo(applyId);
        }
        if (applyCount > 0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 查看投放申请
     *
     * @param applyId 投放申请标识
     * @return 投放申请信息
     */
    @Override
    public ApplyInfoVo getApply(Long applyId) {

        //1.封装id
        ApplyInfoBo applyInfoBo = new ApplyInfoBo();
        applyInfoBo.setId(applyId);
        ApplyContentBo applyContentBo = new ApplyContentBo();
        applyInfoBo.setApplyContentBo(applyContentBo);
        //2.调用查找方法
        ApplyInfoVo applyInfoVo = this.getApplyList(applyInfoBo).get(0);

        return applyInfoVo;
    }

    /**
     * 查询投放申请
     *
     * @param applyInfoBo 查询信息，仅包括标题以及状态
     * @return查询到的投放申请信息列表
     */
    @Override
    public List<ApplyInfoVo> getApplyList(ApplyInfoBo applyInfoBo) {

        List<ApplyInfoVo> applyInfoVoSearch = new ArrayList<>();
        //1.根据状态查询对应的信息
        ApplyInfo applyInfo = new ApplyInfo();
        applyInfo.setId(applyInfoBo.getId());
        applyInfo.setStatus(applyInfoBo.getStatus());

        List<ApplyInfo> applyInfos = applyInfoDao.searchApplyInfo(applyInfo);
        //2.遍历判断是否符合标题要求
        for (ApplyInfo applyInfoItem : applyInfos){
            List<ApplyContentSpScDetailVo> applyContentSpScDetailVoSearch = new ArrayList<>();

            //3.1根据投放申请id以及标题信息查询下面的内容信息
            ApplyContent applyContent = new ApplyContent();
            applyContent.setApplyId(applyInfoItem.getId());
            //3.2查询的标题信息
            applyContent.setTitle(applyInfoBo.getApplyContentBo().getTitle());

            List<ApplyContent> applyContents = applyContentDao.searchApplyContent(applyContent);
            //3.3大于0说明在该数据状态下标题对应，将该条信息保存到Vo
            if (applyContents.size() > 0){
                //3.3.1保存投放申请的信息
                ApplyInfoVo applyInfoVo = new ApplyInfoVo();
                applyInfoVo.setId(applyInfoItem.getId());
                applyInfoVo.setProject(applyInfoItem.getProject());
                applyInfoVo.setLinkManName(applyInfoItem.getLinkManName());
                applyInfoVo.setTel(applyInfoItem.getTel());
                applyInfoVo.setStartTime(applyInfoItem.getStartTime());
                applyInfoVo.setEndTime(applyInfoItem.getEndTime());
                applyInfoVo.setCreateTime(applyInfoItem.getCreateTime());
                applyInfoVo.setUpdateTime(applyInfoItem.getUpdateTime());
                applyInfoVo.setSubmitTime(applyInfoItem.getSubmitTime());
                applyInfoVo.setStatus(applyInfoItem.getStatus());

                //3.3.2保存投放申请内容信息
                ApplyContentVo applyContentVo = new ApplyContentVo();
                applyContentVo.setId(applyContents.get(0).getId());
                applyContentVo.setTitle(applyContents.get(0).getTitle());
                applyContentVo.setSpScType(applyContents.get(0).getSpScType());
                applyContentVo.setLayStyle(applyContents.get(0).getLayStyle());

                //3.4根据内容id查询分屏明细
                ApplyContentSpScDetail applyContentSpScDetail = new ApplyContentSpScDetail();
                applyContentSpScDetail.setApplyContentId(applyContents.get(0).getId());
                List<ApplyContentSpScDetail> detailList = applyContentSpScDetailDao.searchApplyContentSpScDetail(applyContentSpScDetail);
                //遍历数据
                if (detailList.size() > 0){
                    for (ApplyContentSpScDetail detail : detailList){
                        ApplyContentSpScDetailVo applyContentSpScDetailVo = new ApplyContentSpScDetailVo();
                        applyContentSpScDetailVo.setId(detail.getId());
                        applyContentSpScDetailVo.setType(detail.getType());
                        applyContentSpScDetailVo.setScId(detail.getScId());

                        //3.5根据不同的type决定查找哪种数据
                        //文字
                        if (detail.getType() == 0){
                            ApplyContentSpScDetailTextVo applyContentSpScDetailTextVo = new ApplyContentSpScDetailTextVo();
                            //根据分屏明细id查找数据
                            ApplyContentSpScDetailText applyContentSpScDetailText = new ApplyContentSpScDetailText();
                            applyContentSpScDetailText.setApplyContentSpScDetailId(detail.getId());
                            List<ApplyContentSpScDetailText> applyContentSpScDetailTexts = applyContentSpScDetailTextDao.searchApplyContentSpScDetailText(applyContentSpScDetailText);
                            //将查找到的数据赋值给vo
                            if (applyContentSpScDetailTexts.size() > 0){
                                applyContentSpScDetailTextVo.setId(applyContentSpScDetailTexts.get(0).getId());
                                applyContentSpScDetailTextVo.setImageUrl(applyContentSpScDetailTexts.get(0).getImageUrl());
                                applyContentSpScDetailTextVo.setLocation(applyContentSpScDetailTexts.get(0).getLocation());
                                applyContentSpScDetailTextVo.setFontType(applyContentSpScDetailTexts.get(0).getFontType());
                                applyContentSpScDetailTextVo.setFontSize(applyContentSpScDetailTexts.get(0).getFontSize());
                                applyContentSpScDetailTextVo.setFontColor(applyContentSpScDetailTexts.get(0).getFontColor());
                                applyContentSpScDetailTextVo.setTextContent(applyContentSpScDetailTexts.get(0).getTextContent());

                                //将vo赋值给上层vo
                                applyContentSpScDetailVo.setApplyContentSpScDetailTextVo(applyContentSpScDetailTextVo);
                            }
                        }
                        //海报
                        else if (detail.getType() == 1){
                            ApplyContentSpScDetailPosterVo applyContentSpScDetailPosterVo = new ApplyContentSpScDetailPosterVo();
                            //根据分屏明细id查询数据
                            ApplyContentSpScDetailPoster applyContentSpScDetailPoster = new ApplyContentSpScDetailPoster();
                            applyContentSpScDetailPoster.setApplyContentSpScDetailId(detail.getId());
                            List<ApplyContentSpScDetailPoster> applyContentSpScDetailPosters = applyContentSpScDetailPosterDao.searchApplyContentSpScDetailPoster(applyContentSpScDetailPoster);
                            //将查找到的数据赋值给vo
                            if (applyContentSpScDetailPosters.size() > 0){
                                applyContentSpScDetailPosterVo.setId(applyContentSpScDetailPosters.get(0).getId());
                                applyContentSpScDetailPosterVo.setPosterUrl(applyContentSpScDetailPosters.get(0).getPosterUrl());
                                applyContentSpScDetailPosterVo.setResolution(applyContentSpScDetailPosters.get(0).getResolution());

                                //将vo赋值给上层vo
                                applyContentSpScDetailVo.setApplyContentSpScDetailPosterVo(applyContentSpScDetailPosterVo);
                            }
                        }
                        //视频
                        else if (detail.getType() == 2){
                            ApplyContentSpScDetailVideoVo applyContentSpScDetailVideoVo = new ApplyContentSpScDetailVideoVo();

                            //根据分屏明细id查询数据
                            ApplyContentSpScDetailVideo applyContentSpScDetailVideo = new ApplyContentSpScDetailVideo();
                            applyContentSpScDetailVideo.setApplyContentSpScDetailId(detail.getId());
                            List<ApplyContentSpScDetailVideo> applyContentSpScDetailVideos = applyContentSpScDetailVideoDao.searchApplyContentSpScDetailVideo(applyContentSpScDetailVideo);
                            //将查找到的数据赋值给vo
                            if (applyContentSpScDetailVideos.size() > 0){
                                applyContentSpScDetailVideoVo.setId(applyContentSpScDetailVideos.get(0).getId());
                                applyContentSpScDetailVideoVo.setVideoUrl(applyContentSpScDetailVideos.get(0).getVideoUrl());
                                applyContentSpScDetailVideoVo.setTotalTime(applyContentSpScDetailVideos.get(0).getTotalTime());
                                applyContentSpScDetailVideoVo.setResolution(applyContentSpScDetailVideos.get(0).getResolution());

                                //将vo数据赋值给上层vo
                                applyContentSpScDetailVo.setApplyContentSpScDetailVideoVo(applyContentSpScDetailVideoVo);
                            }
                        }

                        //将数据插入到列表
                        applyContentSpScDetailVoSearch.add(applyContentSpScDetailVo);
                    }
                }
                //3.5将列表赋值给内容信息
                applyContentVo.setApplyContentSpScDetailVoList(applyContentSpScDetailVoSearch);
                //将内容信息vofu值给投放申请vo
                applyInfoVo.setApplyContentVo(applyContentVo);
                //将投放申请信息vo保存到列表
                applyInfoVoSearch.add(applyInfoVo);

            }
        }

        return applyInfoVoSearch;
    }

    /**
     * 预览投放申请
     *
     * @param applyId 预览的投放申请的id标识
     * @return投放申请vo信息
     */
    @Override
    public ApplyInfoVo previewApply(Long applyId) {
        //1.封装id
        ApplyInfoBo applyInfoBo = new ApplyInfoBo();
        applyInfoBo.setId(applyId);
        ApplyContentBo applyContentBo = new ApplyContentBo();
        applyInfoBo.setApplyContentBo(applyContentBo);
        //2.调用查找方法
        ApplyInfoVo applyInfoVo = this.getApplyList(applyInfoBo).get(0);

        return applyInfoVo;
    }

    /**
     * 提交投放申请
     *
     * @param applyId 投放申请信息标识
     * @param status  投放申请信息要修改的状态
     * @return
     */
    @Override
    public Boolean submitApply(Long applyId, Integer status) {
        int  flag=0;
        //1.根据id获取投放申请信息
        ApplyInfo applyInfo = applyInfoDao.getApplyInfoById(applyId);
        //2.判断状态是否符合
        if (applyInfo.getStatus()==3){
            applyInfo.setStatus(2);
            applyInfo.setUpdateTime(new Date());
            flag = applyInfoDao.updateApplyInfo(applyInfo);
        }else{
            throw new RuntimeException("状态不符合");
        }

        return flag>0;
    }

    /**
     * 审核投放申请
     *
     * @param applyId 审核的投放申请的id
     * @param status  审核后的状态
     * @return
     */
    @Override
    public Boolean checkApply(Long applyId, Integer status) {
        int flag = 0;
        int flag2 = 0;
        int flag3 = 0;
        int flag4 = 0;
        int flag5 = 0;
        //1.根据投放信息标识查询投放申请信息
        ApplyInfo applyInfoById = applyInfoDao.getApplyInfoById(applyId);
        //2.获取投放申请信息的内容标题
        ApplyContent applyContent = new ApplyContent();
        applyContent.setApplyId(applyId);
        List<ApplyContent> applyContents = applyContentDao.searchApplyContent(applyContent);
        if (applyContents.size() > 0) {
            String title= applyContents.get(0).getTitle();
            //2.验证状态是否为待审核
            if (applyInfoById.getStatus()==2) {
                //3.修改审核状态
                applyInfoById.setStatus(status);
                flag = applyInfoDao.updateApplyInfo(applyInfoById);
                //4.审核完成后添加审核记录
                //4.1实体化数据
                CheckRecordInfo checkRecordInfo = new CheckRecordInfo();
                checkRecordInfo.setApplyId(applyId);
                checkRecordInfo.setApplyTitle(title);
                checkRecordInfo.setApplyManName("石景坤");
                checkRecordInfo.setCheckManName(applyInfoById.getLinkManName());
                checkRecordInfo.setCheckTime(new Date());
                checkRecordInfo.setCheckOpinion(status==0?"通过":"驳回");

                //4.3调用层处理数据
                flag2 = checkRecordInfoDao.insertCheckRecordInfo(checkRecordInfo);

                //5.审核通过后生成广告信息并添加
                if (status == 0){
                    //1广告信息实体化
                    AdInfo adInfo = new AdInfo();
                    adInfo.setApplyId(applyId);
                    adInfo.setAdTitle(title);
                    adInfo.setSpScType(applyContents.get(0).getSpScType());
                    adInfo.setLayStyle(applyContents.get(0).getLayStyle());
                    adInfo.setStatus(0);
                    adInfo.setCreateTime(new Date());

                    //1.2调用dao层方法处理数据
                    flag3 = adInfoDao.insertAdInfo(adInfo);
                    if (flag3>0){
                        //2.插入广告分屏明细
                        //2.1查询插入的广告标识
                        long adId = adInfoDao.searchAdInfo(adInfo).get(0).getId();
                        //2.2查询2投放申请内容分屏明细
                        //封装投放内容id
                        ApplyContentSpScDetail applyContentSpScDetail = new ApplyContentSpScDetail();
                        applyContentSpScDetail.setApplyContentId(applyContents.get(0).getId());
                        List<ApplyContentSpScDetail> detailList = applyContentSpScDetailDao.searchApplyContentSpScDetail(applyContentSpScDetail);
                        for (ApplyContentSpScDetail detail : detailList) {
                            //2.3实体化广告分屏明细
                            AdSpScDetail adSpScDetail = new AdSpScDetail();
                            adSpScDetail.setAdId(adId);
                            adSpScDetail.setType(detail.getType());
                            adSpScDetail.setScId(detail.getScId());

                            //2.4调用dao层处理数据
                            flag4 = adSpScDetailDao.insertAdSpScDetail(adSpScDetail);

                            //分屏明细插入成功后，插入详细数据
                            if (flag4>0){
                                //根据不通的数据类型分别处理
                                //获取插入的广告分屏明细id
                                long adDetailId = adSpScDetailDao.searchAdSpScDetail(adSpScDetail).get(0).getId();
                                //文字
                                if (detail.getType() == 0){
                                    //1.根据投放分屏明细id获取数据
                                    ApplyContentSpScDetailText applyContentSpScDetailText = new ApplyContentSpScDetailText();
                                    applyContentSpScDetailText.setApplyContentSpScDetailId(adSpScDetail.getId());
                                    List<ApplyContentSpScDetailText> applyContentSpScDetailTexts = applyContentSpScDetailTextDao.searchApplyContentSpScDetailText(applyContentSpScDetailText);

                                    //2.实体化广告数据
                                    AdSpScDetailText adSpScDetailText = new AdSpScDetailText();
                                    adSpScDetailText.setImageUrl(applyContentSpScDetailTexts.get(0).getImageUrl());
                                    adSpScDetailText.setLocation(applyContentSpScDetailTexts.get(0).getLocation());
                                    adSpScDetailText.setFontSize(applyContentSpScDetailTexts.get(0).getFontSize());
                                    adSpScDetailText.setFontType(applyContentSpScDetailTexts.get(0).getFontType());
                                    adSpScDetailText.setFontColor(applyContentSpScDetailTexts.get(0).getFontColor());
                                    adSpScDetailText.setTextContent(applyContentSpScDetailTexts.get(0).getTextContent());
                                    adSpScDetailText.setAdSpScDetailId(adDetailId);

                                    //3.调用dao方法处理数据
                                    flag5 = adSpScDetailTextDao.insertAdSpScDetailText(adSpScDetailText);
                                }
                                //海报
                                else if (detail.getType() == 1){
                                    //1.根据投放分屏明细id获取数据
                                    ApplyContentSpScDetailPoster  applyContentSpScDetailPoster =new ApplyContentSpScDetailPoster();
                                    applyContentSpScDetailPoster.setApplyContentSpScDetailId(adSpScDetail.getId());
                                    List<ApplyContentSpScDetailPoster> applyContentSpScDetailPosters = applyContentSpScDetailPosterDao.searchApplyContentSpScDetailPoster(applyContentSpScDetailPoster);

                                    //2.实体化广告海报数据
                                    AdSpScDetailPoster adSpScDetailPoster = new AdSpScDetailPoster();
                                    adSpScDetailPoster.setPosterUrl(applyContentSpScDetailPosters.get(0).getPosterUrl());
                                    adSpScDetailPoster.setResolution(applyContentSpScDetailPosters.get(0).getResolution());
                                    adSpScDetailPoster.setAdSpScDetailId(adDetailId);

                                    //3.调用dao层处理数据
                                    flag5 = adSpScDetailPosterDao.insertAdSpScDetailPoster(adSpScDetailPoster);
                                }
                                //视频
                                else if (detail.getType() == 2){
                                    //1.根据投放分屏明细id获取数据
                                    ApplyContentSpScDetailVideo applyContentSpScDetailVideo =new ApplyContentSpScDetailVideo();
                                    applyContentSpScDetailVideo.setApplyContentSpScDetailId(adSpScDetail.getId());
                                    List<ApplyContentSpScDetailVideo> applyContentSpScDetailVideos = applyContentSpScDetailVideoDao.searchApplyContentSpScDetailVideo(applyContentSpScDetailVideo);

                                    //2.实体化广告视频数据
                                    AdSpScDetailVideo adSpScDetailVideo = new AdSpScDetailVideo();
                                    adSpScDetailVideo.setVideoUrl(applyContentSpScDetailVideos.get(0).getVideoUrl());
                                    adSpScDetailVideo.setTotalTime(applyContentSpScDetailVideos.get(0).getTotalTime());
                                    adSpScDetailVideo.setResolution(applyContentSpScDetailVideos.get(0).getResolution());
                                    adSpScDetailVideo.setAdSpScDetailId(adDetailId);

                                    //3.调用dao处理数据
                                    flag5 = adSpScDetailVideoDao.insertAdSpScDetailVideo(adSpScDetailVideo);
                                }

                            }
                        }
                    }
                }
                //5.审核通过后生成广告信息并添加
            }else{
                throw new RuntimeException("状态不符合");
            }
        }

        return flag>0 && flag2>0;
    }

    /**
     * 修改投放申请
     *
     * @param applyInfoBo 新的投放申请信息
     * @return 是否成功
     */
    @Override
    public Boolean updateApply(ApplyInfoBo applyInfoBo) {

        int applyflag = 0;
        int contentflag = 0;
        int applyspscflag = 0;
        int deleteflag = 0;
        int insertflag = 0;
        int contentdetailLength = applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().size();

        long applyId;
        long contentId;
        long spscdetailId =0;

        //1.判断限制的条件
        if (applyInfoBo==null){
            throw new IllegalArgumentException("新的信息不能为空");
        }
        //1.2根据id获取旧的投放申请信息信息，并将不可更改信息更新
        ApplyInfo oldApplyInfo = applyInfoDao.getApplyInfoById(applyInfoBo.getId());
        ApplyInfo newApplyInfo = new ApplyInfo();
        applyId = oldApplyInfo.getId();
        //更新项的id
        newApplyInfo.setId(oldApplyInfo.getId());
        newApplyInfo.setProject(applyInfoBo.getProject());
        newApplyInfo.setLinkManName(applyInfoBo.getLinkManName());
        newApplyInfo.setTel(applyInfoBo.getTel());
        newApplyInfo.setStartTime(applyInfoBo.getStartTime());
        newApplyInfo.setEndTime(applyInfoBo.getEndTime());
        //创建时间使用旧的信息
        newApplyInfo.setCreateTime(oldApplyInfo.getCreateTime());
        newApplyInfo.setUpdateTime(new Date());
        newApplyInfo.setSubmitTime(oldApplyInfo.getSubmitTime());
        newApplyInfo.setStatus(applyInfoBo.getStatus());
        //1.3更新投放申请信息
        applyflag = applyInfoDao.updateApplyInfo(newApplyInfo);

        //更新成功继续更新
        if (applyflag>0){
            //1.判断投放内容是否为空
            if (applyInfoBo.getApplyContentBo()==null){
                throw new IllegalArgumentException("投放申请内容不能为空");
            }
            //2.根据投放申请id获取投放申请内容信息
            //2.1封装投放申请内容对象
            ApplyContent applyContent = new ApplyContent();
            ApplyContent newApplyContent = new ApplyContent();
            applyContent.setApplyId(applyId);
            //2.2查找对应的信息并保存
            List<ApplyContent> applyContents = applyContentDao.searchApplyContent(applyContent);
            //2.3将修改的信息保存
            contentId = applyContents.get(0).getId();
            newApplyContent.setApplyId(applyId);
            newApplyContent.setId(applyContents.get(0).getId());
            newApplyContent.setTitle(applyInfoBo.getApplyContentBo().getTitle());
            newApplyContent.setSpScType(applyInfoBo.getApplyContentBo().getSpScType());
            newApplyContent.setLayStyle(applyInfoBo.getApplyContentBo().getLayStyle());
            //2.4更新信息
            contentflag =  applyContentDao.updateApplyContent(newApplyContent);

            //更心完成后继续更新
            /**
             * 分屏明细逻辑更新逻辑
             *
             * 为了解决数据减少或者增加的问题，
             * 先对旧数据进行删除，
             * 之后将新的数据添加到数据库中
             */

            if (contentflag>0){
                //3.1根据更新内容id查询分屏明细
                ApplyContentSpScDetail applyContentSpScDetail = new ApplyContentSpScDetail();
                applyContentSpScDetail.setApplyContentId(contentId);
                List<ApplyContentSpScDetail> detailList = applyContentSpScDetailDao.searchApplyContentSpScDetail(applyContentSpScDetail);
                //3.2遍历寻找下层的数据并进行删除
                for (ApplyContentSpScDetail detailSpScDetail : detailList) {
                    spscdetailId = detailSpScDetail.getId();
                    //3.3根据类型决定执行哪一项
                    //文字
                    if (detailSpScDetail.getType() == 0){
                        //3.4.1根据分屏明细id查询数据
                        ApplyContentSpScDetailText applyContentSpScDetailText = new ApplyContentSpScDetailText();
                        applyContentSpScDetailText.setApplyContentSpScDetailId(spscdetailId);
                        List<ApplyContentSpScDetailText> applyContentSpScDetailTexts = applyContentSpScDetailTextDao.searchApplyContentSpScDetailText(applyContentSpScDetailText);
                        //3.4.2执行删除操作
                        deleteflag = applyContentSpScDetailTextDao.deleteApplyContentSpScDetailText(applyContentSpScDetailTexts.get(0).getId());
                    }
                    else if (detailSpScDetail.getType() == 1){
                        //3.4.1根据分屏明细id查询数据
                        ApplyContentSpScDetailPoster applyContentSpScDetailPoster = new ApplyContentSpScDetailPoster();
                        applyContentSpScDetailPoster.setApplyContentSpScDetailId(spscdetailId);
                        List<ApplyContentSpScDetailPoster> applyContentSpScDetailPosters = applyContentSpScDetailPosterDao.searchApplyContentSpScDetailPoster(applyContentSpScDetailPoster);
                        //3.4.2执行删除操作
                        deleteflag = applyContentSpScDetailPosterDao.deleteApplyContentSpScDetailPoster(applyContentSpScDetailPosters.get(0).getId());
                    }else{
                        //3.4.1根据分屏明细id查询数据
                        ApplyContentSpScDetailVideo applyContentSpScDetailVideo = new ApplyContentSpScDetailVideo();
                        applyContentSpScDetailVideo.setApplyContentSpScDetailId(spscdetailId);
                        List<ApplyContentSpScDetailVideo> applyContentSpScDetailVideos = applyContentSpScDetailVideoDao.searchApplyContentSpScDetailVideo(applyContentSpScDetailVideo);
                        //3.4.2执行删除操作
                        deleteflag = applyContentSpScDetailVideoDao.deleteApplyContentSpScDetailVideo(applyContentSpScDetailVideos.get(0).getId());
                    }
                }
                //删除完毕之后，根据新列表的数量决定留或者添加
                if (deleteflag>0){
                    //如果新的数量小于等于原来的数量
                    if (contentdetailLength <= detailList.size()){
                        int index =0;
                        for (ApplyContentSpScDetail detailSpScDetail : detailList){
                            spscdetailId = detailSpScDetail.getId();
                            //判断是否超出新的范围，没有超出就更改并添加新的信息，超出则删除旧的分屏信息
                            if (index <= contentdetailLength-1){
                                //保存新的信息
                                ApplyContentSpScDetail newApplyContentSpScDetail = new ApplyContentSpScDetail();
                                newApplyContentSpScDetail.setApplyContentId(contentId);
                                newApplyContentSpScDetail.setId(spscdetailId);
                                newApplyContentSpScDetail.setType(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getType());
                                newApplyContentSpScDetail.setScId(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getScId());

                                //调用更新方法
                                applyspscflag = applyContentSpScDetailDao.updateApplyContentSpScDetail(newApplyContentSpScDetail);

                                //更新完成后插入新的信息
                                if (applyspscflag>0){
                                    if (newApplyContentSpScDetail.getType() == 0){
                                        //1.2实体化数据
                                        ApplyContentSpScDetailText applyContentSpScDetailText = new ApplyContentSpScDetailText();
                                        applyContentSpScDetailText.setImageUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getImageUrl());
                                        applyContentSpScDetailText.setLocation(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getLocation());
                                        applyContentSpScDetailText.setFontType(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getFontType());
                                        applyContentSpScDetailText.setFontSize(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getFontSize());
                                        applyContentSpScDetailText.setFontColor(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getFontColor());
                                        applyContentSpScDetailText.setTextContent(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getTextContent());
                                        applyContentSpScDetailText.setApplyContentSpScDetailId(spscdetailId);

                                        //2.2调用dao处理数据
                                        insertflag = applyContentSpScDetailTextDao.insertApplyContentSpScDetailText(applyContentSpScDetailText);
                                    }
                                    //2.海报
                                    else if (newApplyContentSpScDetail.getType() == 1) {
                                        //2.1实体化数据
                                        ApplyContentSpScDetailPoster applyContentSpScDetailPoster =new ApplyContentSpScDetailPoster();
                                        applyContentSpScDetailPoster.setPosterUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailPosterBo().getPosterUrl());
                                        applyContentSpScDetailPoster.setResolution(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailPosterBo().getResolution());
                                        applyContentSpScDetailPoster.setApplyContentSpScDetailId(spscdetailId);

                                        //2.2调用dao处理数据
                                        insertflag = applyContentSpScDetailPosterDao.insertApplyContentSpScDetailPoster(applyContentSpScDetailPoster);
                                    }
                                    //3.视频
                                    else if (newApplyContentSpScDetail.getType() == 2){
                                        //3.1实体化数据
                                        ApplyContentSpScDetailVideo applyContentSpScDetailVideo =new ApplyContentSpScDetailVideo();
                                        applyContentSpScDetailVideo.setVideoUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailVideoBo().getVideoUrl());
                                        applyContentSpScDetailVideo.setTotalTime(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailVideoBo().getTotalTime());
                                        applyContentSpScDetailVideo.setResolution(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailVideoBo().getResolution());
                                        applyContentSpScDetailVideo.setApplyContentSpScDetailId(spscdetailId);

                                        //3.2调用dao层处理数据
                                        insertflag = applyContentSpScDetailVideoDao.insertApplyContentSpScDetailVideo(applyContentSpScDetailVideo);

                                    }

                                }
                            }
                            else{
                                applyContentSpScDetailDao.deleteApplyContentSpScDetail(spscdetailId);
                            }
                            index++;
                        }
                    }
                    else{
                        int index =0;
                        //更新跟原来数量相同的数据
                        for (ApplyContentSpScDetail detailSpScDetail : detailList){
                            spscdetailId = detailSpScDetail.getId();
                            //判断是否超出新的范围，没有超出就更改并添加新的信息，超出则删除旧的分屏信息
                            if (index <= contentdetailLength-1){
                                //保存新的信息
                                ApplyContentSpScDetail newApplyContentSpScDetail = new ApplyContentSpScDetail();
                                newApplyContentSpScDetail.setApplyContentId(contentId);
                                newApplyContentSpScDetail.setId(spscdetailId);
                                newApplyContentSpScDetail.setType(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getType());
                                newApplyContentSpScDetail.setScId(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getScId());

                                //调用更新方法
                                applyspscflag = applyContentSpScDetailDao.updateApplyContentSpScDetail(newApplyContentSpScDetail);

                                //更新完成后插入新的信息
                                if (applyspscflag>0){
                                    if (newApplyContentSpScDetail.getType() == 0){
                                        //1.2实体化数据
                                        ApplyContentSpScDetailText applyContentSpScDetailText = new ApplyContentSpScDetailText();
                                        applyContentSpScDetailText.setImageUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getImageUrl());
                                        applyContentSpScDetailText.setLocation(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getLocation());
                                        applyContentSpScDetailText.setFontType(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getFontType());
                                        applyContentSpScDetailText.setFontSize(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getFontSize());
                                        applyContentSpScDetailText.setFontColor(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getFontColor());
                                        applyContentSpScDetailText.setTextContent(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailTextBo().getTextContent());
                                        applyContentSpScDetailText.setApplyContentSpScDetailId(spscdetailId);

                                        //2.2调用dao处理数据
                                        insertflag = applyContentSpScDetailTextDao.insertApplyContentSpScDetailText(applyContentSpScDetailText);
                                    }
                                    //2.海报
                                    else if (newApplyContentSpScDetail.getType() == 1) {
                                        //2.1实体化数据
                                        ApplyContentSpScDetailPoster applyContentSpScDetailPoster =new ApplyContentSpScDetailPoster();
                                        applyContentSpScDetailPoster.setPosterUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailPosterBo().getPosterUrl());
                                        applyContentSpScDetailPoster.setResolution(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailPosterBo().getResolution());
                                        applyContentSpScDetailPoster.setApplyContentSpScDetailId(spscdetailId);

                                        //2.2调用dao处理数据
                                        insertflag = applyContentSpScDetailPosterDao.insertApplyContentSpScDetailPoster(applyContentSpScDetailPoster);
                                    }
                                    //3.视频
                                    else if (newApplyContentSpScDetail.getType() == 2){
                                        //3.1实体化数据
                                        ApplyContentSpScDetailVideo applyContentSpScDetailVideo =new ApplyContentSpScDetailVideo();
                                        applyContentSpScDetailVideo.setVideoUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailVideoBo().getVideoUrl());
                                        applyContentSpScDetailVideo.setTotalTime(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailVideoBo().getTotalTime());
                                        applyContentSpScDetailVideo.setResolution(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(index).getApplyContentSpScDetailVideoBo().getResolution());
                                        applyContentSpScDetailVideo.setApplyContentSpScDetailId(spscdetailId);

                                        //3.2调用dao层处理数据
                                        insertflag = applyContentSpScDetailVideoDao.insertApplyContentSpScDetailVideo(applyContentSpScDetailVideo);

                                    }

                                }
                            }
                            index++;
                    }
                        //添加超出的数据
                        for (int i =index;i<contentdetailLength;i++){
                            //添加分屏明细
                            //3.2将投放申请分屏数据实体化
                            ApplyContentSpScDetail applyContentSpScDetailnew = new ApplyContentSpScDetail();
                            applyContentSpScDetail.setType(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getType());
                            applyContentSpScDetail.setScId(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getScId());
                            applyContentSpScDetail.setApplyContentId(contentId);

                            //4.3调用dao插入数据
                            insertflag = applyContentSpScDetailDao.insertApplyContentSpScDetail(applyContentSpScDetail);
                            //成功后插入投放详细数据
                            if (insertflag > 0) {
                                //4.1查询光告分屏明细id
                                List<ApplyContentSpScDetail> applyContentSpScDetails = applyContentSpScDetailDao.searchApplyContentSpScDetail(applyContentSpScDetail);
                                if (applyContentSpScDetails.size() > 0) {
                                    spscdetailId = applyContentSpScDetails.get(0).getId();
                                }
                                //4.2根据投放广告类型决定进行哪一项实体化
                                //1文字
                                if (applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getType() == 0){
                                    //1.2实体化数据
                                    ApplyContentSpScDetailText applyContentSpScDetailText = new ApplyContentSpScDetailText();
                                    applyContentSpScDetailText.setImageUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailTextBo().getImageUrl());
                                    applyContentSpScDetailText.setLocation(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailTextBo().getLocation());
                                    applyContentSpScDetailText.setFontType(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailTextBo().getFontType());
                                    applyContentSpScDetailText.setFontSize(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailTextBo().getFontSize());
                                    applyContentSpScDetailText.setFontColor(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailTextBo().getFontColor());
                                    applyContentSpScDetailText.setTextContent(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailTextBo().getTextContent());
                                    applyContentSpScDetailText.setApplyContentSpScDetailId(spscdetailId);

                                    //2.2调用dao处理数据
                                    insertflag = applyContentSpScDetailTextDao.insertApplyContentSpScDetailText(applyContentSpScDetailText);
                                }
                                //2.海报
                                else if (applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getType() == 1) {
                                    //2.1实体化数据
                                    ApplyContentSpScDetailPoster applyContentSpScDetailPoster =new ApplyContentSpScDetailPoster();
                                    applyContentSpScDetailPoster.setPosterUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailPosterBo().getPosterUrl());
                                    applyContentSpScDetailPoster.setResolution(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailPosterBo().getResolution());
                                    applyContentSpScDetailPoster.setApplyContentSpScDetailId(spscdetailId);

                                    //2.2调用dao处理数据
                                    insertflag = applyContentSpScDetailPosterDao.insertApplyContentSpScDetailPoster(applyContentSpScDetailPoster);
                                }
                                //3.视频
                                else if (applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getType() == 2){
                                    //3.1实体化数据
                                    ApplyContentSpScDetailVideo applyContentSpScDetailVideo =new ApplyContentSpScDetailVideo();
                                    applyContentSpScDetailVideo.setVideoUrl(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailVideoBo().getVideoUrl());
                                    applyContentSpScDetailVideo.setTotalTime(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailVideoBo().getTotalTime());
                                    applyContentSpScDetailVideo.setResolution(applyInfoBo.getApplyContentBo().getApplyContentSpScDetailBoList().get(i).getApplyContentSpScDetailVideoBo().getResolution());
                                    applyContentSpScDetailVideo.setApplyContentSpScDetailId(spscdetailId);

                                    //3.2调用dao层处理数据
                                    insertflag = applyContentSpScDetailVideoDao.insertApplyContentSpScDetailVideo(applyContentSpScDetailVideo);

                                }
                            }
                        }
                    }
                }
            }

        }
        if (applyspscflag>0 && insertflag>0 && applyflag>0){
            return true;
        }
        return false;
    }
}
